package com.jiezhuo.service.impl.jss;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiezhuo.entity.LoginUser;
import com.jiezhuo.entity.cmeduSchool.TJzg;
import com.jiezhuo.entity.jssgl.JssXtAppmenu;
import com.jiezhuo.entity.jssgl.JssXtUserlist;
import com.jiezhuo.mapper.jss.JssXtAppmenuMapper;
import com.jiezhuo.mapper.jss.JssXtUserlistMapper;
import com.jiezhuo.service.jss.JssXtUserlistService;
import com.jiezhuo.service.jzg.TJzgService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

/**
 * 服务接口实现
 *
 * @author kancy
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2024-06-13 08:48:15
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class JssXtUserlistServiceImpl extends ServiceImpl<JssXtUserlistMapper, JssXtUserlist> implements JssXtUserlistService {
    private final JssXtUserlistMapper jssXtUserlistMapper;

    private final TJzgService tJzgService;

    @Override
    public JssXtUserlist getAdminUserOne() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        String userId = loginUser.getUser().getUserid();
        QueryWrapper<JssXtUserlist> JssXtUserlistQueryWrapper = new QueryWrapper<>();
        JssXtUserlistQueryWrapper.eq("UserId", userId);
        JssXtUserlist jssXtUserlistServiceOne = getOne(JssXtUserlistQueryWrapper);


        QueryWrapper<TJzg> wrapper = new QueryWrapper<>();
        wrapper.eq("TeacherId", jssXtUserlistServiceOne.getUserid());
        TJzg jzg = tJzgService.getOne(wrapper);
        jssXtUserlistServiceOne.setJzg(jzg);

        return jssXtUserlistServiceOne;
    }

    @Override
    public Boolean isRoleXiao() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        String userId = loginUser.getUser().getUserid();
        QueryWrapper<JssXtUserlist> JssXtUserlistQueryWrapper = new QueryWrapper<>();
        JssXtUserlistQueryWrapper.eq("UserId", userId);
        JssXtUserlist jssXtUserlistServiceOne = getOne(JssXtUserlistQueryWrapper);

        if (jssXtUserlistServiceOne.getJb().equals("校级")) {
            return true;
        }

        return false;
    }
}